<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

    <title>粉粉管理系统</title>

    <!-- Bootstrap core CSS -->
    <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

    <!--Animation css-->
    <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

    <!--Icon-fonts css-->
    <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />

    <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">

    <!-- Plugins css -->
    <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

    <!-- DataTables -->
    <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

    <!-- Custom styles for this template -->
    <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">

    <!-- My styles for this template -->
    <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">

</head>

<body>

<!-- Aside Start-->
<!--{template admin_v2/leftside}-->
<!-- Aside Ends-->


<!--Main Content Start -->
<section class="content">

    <!-- Header -->
    <!--{template admin_v2/header}-->
    <!-- Header Ends -->


    <!-- Page Content Start -->
    <!-- ================== -->

    <div class="wraper container-fluid diary-topics">

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">达人堂</h3>
                    </div>
                    <br>
                    <div class="form-inline">
                        <div class="form-group">
                            <label>
                                筛选:
                            </label>
                            <div class="form-group">
                                <select class="form-control" id="label" name="label">
                                    <option value="1">情感鸡汤</option>
                                    <option value="10">搞笑能手</option>
                                    <option value="11">原创达人</option>
                                    <option value="12">二次元</option>
                                    <option value="13">混娱乐圈</option>
                                    <option value="21">活跃榜</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <select class="form-control" id="cyclenum" name="cycle">
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <input type="hidden" value="0" id="lastcycle">
                           <button class="btn btn-danger" id="updateAbility" >生成达人榜</button>
                        </div>
                        <form style="float:right;"  role="form" class="form-inline">
                            <div class="form-group">
                                <input type="text" name="uid" id="uid" placeholder="输入UID" class="form-control">
                            </div>
                            <button class="btn btn-success m-l-10" id="checkUid" type="button">查看</button>
                        </form>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <table id="datatable" class="table table-striped table-bordered">
                                    <thead>
                                    <tr>
                                        <th style="width:5%">
                                            <div class="btn-group" style="margin-bottom: 5px;">
                                                <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    批量操作 <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu">
                                                    <li><a href="#" class='batchAction' data-filter="0" >上线</a></li>
                                                    <li><a href="#" class='batchAction' data-filter="1">下线</a></li>
                                                    <li><a href="#" class='deleteAction'>删除</a></li>
                                                    <li><a href="#" class='batchBodyId' >生成bodyId</a></li>
                                                </ul>
                                            </div>
                                            <label class="cr-styled">
                                                <input type="checkbox" id="batchAll">
                                                <i class="fa"></i>
                                                全选
                                            </label>
                                        </th>
                                        <th style="width: 5%;">UID</th>
                                        <th style="width: 7%;">bodyId</th>
                                        <th style="width: 4%;">类型</th>
                                        <th style="width: 5%;">排序值</th>
                                        <th style="width: 5%;">干预值</th>
                                        <th style="width: 5%;">周期</th>
                                        <th style="width: 5%;">状态</th>
                                        <th style="width: 5%;">创建时间</th>
                                        <th style="width: 5%;">更新时间</th>
                                        <th style="width: 8%;">操作</th>
                                    </tr>
                                    </thead>

                                    <tbody id="viewList">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Page Content Ends -->
    <!-- ================== -->

    <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

    </div><!-- /.modal -->


    <!-- Footer Start -->
    <!--{template admin_v2/footer}-->
    <!-- Footer Ends -->



</section>
<!-- Main Content Ends -->


<!-- js placed at the end of the document so the pages load faster -->
<script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
<script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>

<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>
<script src="<!--{eval echo register_static('laytpl/laytpl.js');}-->"></script>
<script src="<!--{eval echo register_static('layer/layer.js');}-->"></script>
<script src="<!--{eval echo register_static('laydate/laydate.js');}-->"></script>
<script src="<!--{eval echo register_static('laypage/laypage.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>

<!-- Modal-Effect -->
<script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>
<script src="<!--{eval echo register_static('js/common.js');}-->"></script>
<script id="list" type="text/html">
    {{# for(var i=0,len=d.length;i< len;i++){ }}
    <tr>
        <td>
            <label class="cr-styled">
                <input type="checkbox" class="batch" data-uid="{{d[i].uid}}" data-id="{{d[i].id}}">
                <i class="fa"></i>
            </label>
        </td>
        <td><a href="http://ffweb.ffrj.net/profile.php?ac=index&id={{d[i].uid}}">{{d[i].uid}}</a></td>
        <td>{{d[i].typeid}}</td>
        <td>{{laytpl.masterType(d[i].label)}}</td>
        <td>{{d[i].sortnum}}</td>
        <td>{{d[i].setsort}}</td>
        <td>{{laytpl.cycle(d[i].cycle)}}</td>
        <td>{{laytpl.vv(d[i].filter)}}</td>
        <td>{{laytpl.dateTime(d[i].starttime)}}</td>
        <td>{{laytpl.dateTime(d[i].endtime)}}</td>
        <td>
            <div class="btn-group">
                <button type="button" class="btn btn-info">管理</button>
                <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span class="caret"></span>
                    <span class="sr-only">Toggle Dropdown</span>
                </button>
                <ul class="dropdown-menu">
                    <li><a href="javascript:void(0);" class="masterAction" data-filter="1" data-id="{{d[i].id}}">下线</a></li>
                    <li><a href="javascript:void(0);" class="masterAction"  data-filter="0" data-id="{{d[i].id}}">上线</a></li>
                    <li><a href="javascript:void(0);" class="masterVerified"  data-id="{{d[i].id}}">修改排序值</a></li>
                    <li><a href="javascript:void(0);" class="setbodyId" data-id="{{d[i].id}}">修改bodyId</a></li>
                </ul>
            </div>
        </td>
    </tr>
    {{# } }}
</script>
<script type="text/html" id="setsortNum">
    <form action="" class="form-inline">
        干预值：
        <input type="text" class="form-control" id="setsort">
        <button type="button" data-id="{{d.id}}"  class="btn btn-info" id="sort_button">执行</button>
    </form>
</script>
<script type="text/html" id="setcycle">
    <form action="" class="form-inline">
        期数:
        <input type="text" class="form-control" value="{{d.cycle}}" id="newcycle">
        <button type="button"   class="btn btn-info" id="cycle_button">执行</button>
    </form>
</script>
<script type="text/html" id="updateBodyId">
    <form action="" class="form-inline">
        bodyId:
        <input type="text" class="form-control" value="" id="bodyid">
        <button type="button"   class="btn btn-info" data-id="{{d.id}}" id="bodyid_button">执行</button>
    </form>
</script>
<script type="text/javascript">
    var uid = 0;
    var label=1;
    var cycle=1;
    var params = function(){
        return {uid:uid,cycle:cycle,label:label,action:'getAbilityRankList',do:'abilityRank'};
    }
    $(document).on('click','.deleteAction',function () {
        var data={}
        var ids='';
        $("input[class=batch]:checked").each(function() {
            ids+=parseInt($(this).data('id'))+',';
        });
        var idstr=ids.substring(0,ids.length-1);
        data['idstr']=idstr;
        data['action'] = 'deleteAbilityRank';
        data['do'] = 'abilityRank';
        request(data, resDisplay);
    });
    $(document).on('click','.batchAction',function () {
        var data={}
        var filter = $(this).data('filter');
        var ids='';
        $("input[class=batch]:checked").each(function() {
            ids+=parseInt($(this).data('id'))+',';
        });
        var idstr=ids.substring(0,ids.length-1);
        data['idstr']=idstr;
        data['filter']=filter;
        data['action'] = 'setManyFilter';
        data['do'] = 'abilityRank';
        request(data, resDisplay);
    });
    $(document).on('click','.batchBodyId',function(){
        var data={}
        var res=1
        $("input[class=batch]:checked").each(function() {
            data['id']=$(this).data('id');
            data['uid']=$(this).data('uid');
            data['action'] = 'generateBodyId';
            data['do'] = 'abilityRank';
            request(data, function(d){
                if(d){
                }else{
                    res=0;
                }
            });
        });
        if(res==1){
            layer.msg('操作成功');
        }
    });
    $(document).on('click','#batchAll',function(){
        var s = false;
        if($(this).is(':checked')){
            $( "input[class=batch]" ).each(function() {
                $(this).prop('checked',true);
            });
        }else{
            $( "input[class=batch]" ).each(function() {
                $(this).removeAttr('checked');
            });
        }
    });
    $(document).on('click','#bodyid_button',function () {
        var bodyid= $('#bodyid').val();
        var id=$(this).data('id');
        request({'bodyId':bodyid,id:id,'action':'updatebodyId','do':'abilityRank'},resDisplay);
    });
    $(document).on('click','.setbodyId',function(){
        var html = laytpl($("#updateBodyId").html()).render({'id':$(this).data('id')});
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '140px'], //宽高
            title:'设置bodyId',
            content: html,
        });
    });
    $(document).on('click','#cycle_button',function () {
        var cycle = $('#newcycle').val();
        request({'cycle':cycle,'action':'updateAbilityList','do':'abilityRank'},resDisplay);
    });
    $(document).on('click','#updateAbility',function(){
        var data={}
        data['cycle'] = parseInt($('#lastcycle').val());
        var html = laytpl($("#setcycle").html()).render(data);

        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '140px'], //宽高
            title:'设置周期',
            content: html,
        });
    });
    $(document).on('change','#label',function () {
        uid = 0;
        label=$(this).val()
        request(params(), displayRes);
    });
    $(document).on('change','#cyclenum',function () {
        uid = 0;
        cycle=$(this).val()
        request(params(), displayRes);
    });

    $(document).on('click','#checkUid',function () {
        uid = $('#uid').val();
        request(params(), displayRes);
    })

    $(function(){
        request(params(), displayRes);
        request({action:'getAbilityRankCycleNum',do:'abilityRank'},getAbilityRankCycleNum);
    });

    var getAbilityRankCycleNum = function(data){
        var n = parseInt(data.cycle) || 0;
        var str = '';

        for(var i=cycle;i<n+1;i++){
           str+='<option value="'+i+'">第'+i+'期</option>';
        }
        $('#lastcycle').val(n);
        $('#cyclenum').html(str);
    }
    var displayRes = function(data){
        laytpl($('#list').html()).render(data,function(html){
            $('#viewList').html(html);
        });
    }

    $(document).on('click','.masterAction',function(){
        var data={}
        data['id'] = $(this).data('id');
        data['filter'] = $(this).data('filter');
        data['action'] = 'setFilter';
        data['do'] = 'abilityRank';
        request(data, resDisplay);
    });

    $(document).on('click','.masterVerified',function(){
        var data={}
        data['id'] = $(this).data('id');
        var html = laytpl($("#setsortNum").html()).render(data);

        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '140px'], //宽高
            title:'设置排序值',
            content: html,
        });
    });
    $(document).on('click','#sort_button',function(){
        var data = {};
        data['id']= $(this).data('id');
        data['setsort'] = $('#setsort').val();
        data['action']='setSortNum';
        data['do'] = 'abilityRank';
        request(data,resDisplay);

    });

    laytpl.dateTime= function (time) {
        if(!!time){
            return new Date(parseInt(time) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
        }
        return '无';
    }
    laytpl.masterType = function (v) {
        var type = '未知';
        switch(v){
            case "1":
               type = "情感鸡汤";
                break;
            case "10":
                type = "搞笑能手";
                break;
            case "11":
                type = "原创达人";
                break;
            case "12":
                type = "二次元";
                break;
            case "13":
                type = "混娱乐圈";
                break;
            case "21":
                type = "活跃榜";
                break;
        }
        return type;
    }
    laytpl.vv = function (v) {
       if(v == 1){
           return '已下线';
       }
        return '已上线';
    }
    laytpl.cycle=function (v) {
       return '第'+parseInt(v)+'期';
    }
</script>
</body>
</html>
